
#ifdef a
#include<stdio.h>

void InsertSort(int arr[], int size) {
    for (int i = 1; i < size; i++) {
        int end = i - 1;
        int key = arr[i];
        //降序
        while (end >= 0 && arr[end] < key) {
            arr[end + 1] = arr[end];
            end--;
        }
        arr[end + 1] = key;
    }
    return;
}
int main() {
    //创建文件
    FILE* pf1,*pf2;
    pf1 = fopen("in.txt", "w+");
    pf2 = fopen("out.txt", "w+");
    if (!pf1 || !pf2) {
        perror("open error:");
        return -1;
    }
    
    //向in.txt写入数据
    int arr1[10] = { 0,1,2,3,4,5,6,7,8,9 };
    for (int i = 0; i < 10; i++)
        fprintf(pf1, "%d ", arr1[i]);
    rewind(pf1);

    //读取数据
    int arr2[10];
    for (int i = 0; i < 10; i++) {
        fscanf(pf1, "%d", &arr2[i]);
    }
    
    //排序
    InsertSort(arr2, 10);
    
    //将数据写到写入out.txt
    for (int i = 0; i < 10; i++)
        fprintf(pf2, "%d ", arr2[i]);

    fclose(pf1);
    fclose(pf2);
    return 0;
}
#endif
